package cn.nnxy.zentao.service.impl;


import cn.nnxy.zentao.domain.List1User;
import cn.nnxy.zentao.domain.Log;
import cn.nnxy.zentao.domain.User;
import cn.nnxy.zentao.mapper.List1Mapper;
import cn.nnxy.zentao.service.List1;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class List1Impl implements List1 {
    @Autowired
    private List1Mapper list1Mapper;


    @Override
    public List<List1User> queryAlls(String str) {//查询
        if(str==null){
            return list1Mapper.queryUserList();
        }else if(str.equals("所有")){
            return list1Mapper.queryUserList();
        }else if(str.equals("本年")){
            return list1Mapper.queryUserList1();
        }else if(str.equals("已完成")){
            return list1Mapper.queryUserList2();
        }else if(str.equals("未完成")){
            return list1Mapper.queryUserList3();
        }else if(str.equals("最高")){
            return list1Mapper.queryUserList4();
        }else if(str.equals("倒叙")){
            return list1Mapper.queryUserList6();
        }else {
            return list1Mapper.queryUserList5(str);
        }
    }



    @Override
    public void queryDel(String id) {//删除
        List1User user = list1Mapper.DelName(Integer.parseInt(id));
        list1Mapper.queryDelList(Integer.parseInt(id));
        Log log = list1Mapper.queryMax();
        list1Mapper.queryLog(log.getName(),new Date(),"删除了待办："+user.getUpcoming_name());

    }

    @Override
    public List1User queryUpdate(Integer id) {//回显

        return list1Mapper.queryUpdateList(id);
    }

    @Override
    public void queryUpdate2(List1User user) {//修改
        list1Mapper.queryUpdateList2(user.getId(),user.getDates(),user.getType(),
                user.getP(),user.getUpcoming_name(),user.getBegin(),user.getEnd(),
                user.getCondition());
        Log log = list1Mapper.queryMax();
        list1Mapper.queryLog(log.getName(),new Date(),"修改了待办："+user.getUpcoming_name());
    }

    @Override
    public void queryAdd(List1User user) {//添加
        list1Mapper.queryAddList(user.getDates(),user.getType(),
                user.getP(),user.getUpcoming_name(),user.getBegin(),user.getEnd(),
                user.getCondition());
        Log log = list1Mapper.queryMax();
        list1Mapper.queryLog(log.getName(),new Date(),"添加了待办："+user.getUpcoming_name());
    }

    @Override
    public void queryReg(User user) {//注册
        list1Mapper.queryRegUser(user.getUsername(),user.getPassword(),user.getEmail(),
                user.getName(),user.getTelephone(),user.getSex(),user.getBirthday());
        list1Mapper.queryLog(user.getUsername(),new Date(),"注册了禅道");
    }

    @Override
    public void LogUser(String name) {
        list1Mapper.queryLog(name,new Date(),"登录了禅道");
    }

    @Override
    public List<Log> queryLog() {
        return list1Mapper.queryLogList();
    }

    @Override
    public String queryname() {
        Log log = list1Mapper.queryMax();
        return log.getName();
    }
}
